package com.sky.controller.user;


import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
public class ShoppingCartController {
    @Resource
    ShoppingCartService shoppingCartService;
    @PostMapping("/add")
    public Result save(@RequestBody ShoppingCartDTO s){
        log.info("{}",s);
        shoppingCartService.save(s);
        return Result.success();
    }

    @GetMapping("list")
    public Result<List<ShoppingCart>> list(){
       List<ShoppingCart> list =  shoppingCartService.list();
       return Result.success(list);
    }

    @DeleteMapping("clean")
    public Result clean(){
        shoppingCartService.clean();
        return Result.success();
    }
    @PostMapping("/sub")
    public Result sub(ShoppingCartDTO shoppingCartDTO){
      shoppingCartService.sub(shoppingCartDTO);
      return Result.success();
    }
}
